#ifndef __MEMORY_H__
#define __MEMORY_H__

#include "BaseType.h"
#include "IODevice.h"
#include <iostream>
#include <vector>

namespace libemb{
class MemBlock{
public:
    MemBlock();
    ~MemBlock();
    bool m_isUsed;
    void* m_address;
    std::string m_name;
};
class MemoryPool{
public:
    MemoryPool();
    ~MemoryPool();
    bool initPool(int blockNum,int blockSize);
    void* getMemory(const std::string& memoryName,int memorySize);
    bool putMemory(const std::string&  memoryName);
    void showMemory();
private:
    void* m_memory;
    int m_blockNum;
    int m_blockSize;
    int m_poolSize;
    std::vector<MemBlock*> m_memBlocks;
};

typedef enum{
    MEMSHARED_ATTR_SIZE=0,
}MEMSHARED_ATTR_E;

typedef enum{
    MEMSHARED_TYPE_SHM=0,
    MEMSHARED_TYPE_FILE,
}MEMSHARED_TYPE_E;
/**
 *  \file   Memory.h   
 *  \class  MemShared
 *  \brief  共享内存类
 */
class MemShared:public IODevice{
public:
    MemShared(int type);
    virtual ~MemShared();
    virtual bool open(const char *name=NULL, int ioMode=IO_MODE_INVALID);
    virtual bool close();
    virtual int setAttribute(int attr, int value);
    virtual int getAttribute(int attr);
    void* attach();
    int detach();
    
private:
    int m_shmType;
    int m_shmSize;
    void* m_shmAddr;
};
}
#endif
